<template>
  <el-tabs :tab-position="tabPosition" style="height:100px;width: 100%">
    <el-tab-pane label="药品总库存">
      <template>
        <div class="app-container">
          <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="药品名称" prop="drugName">
              <el-input
                v-model="queryParams.drugName"
                placeholder="请输入药品名称"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="药品类型" prop="drugType">
              <el-input
                v-model="queryParams.drugType"
                placeholder="请输入药品类型"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="生产厂家" prop="drugFactory">
              <el-input
                v-model="queryParams.drugFactory"
                placeholder="请输入生产厂家"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="处方类型" prop="drugRecipe">
              <el-input
                v-model="queryParams.drugRecipe"
                placeholder="请输入处方类型"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
            <!--<el-table-column type="selection" width="55" align="center" />-->
            <el-table-column label="药品ID" align="center" prop="drugId" />
            <el-table-column label="药品名称" align="center" prop="drugName" />
            <el-table-column label="药品编码" align="center" prop="drugCode" />
            <el-table-column label="生产厂家" align="center" prop="drugFactory" />
            <el-table-column label="药品类型" align="center" prop="drugType" />
            <el-table-column label="处方类型" align="center" prop="drugRecipe" />
            <el-table-column label="单位" align="center" prop="drugUnit" />
            <el-table-column label="处方价格" align="center" prop="drugPrice" />
            <el-table-column label="库存量" align="center" prop="stockNum" />
            <el-table-column label="预警值" align="center" prop="stockRisk" />
            <el-table-column label="换算量" align="center" prop="stockConvert" />
            <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </template>
    </el-tab-pane>
    <el-tab-pane label="批次库存及价格">
      <template>
        <div class="app-container">
          <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

            <el-form-item label="单据号" prop="drugCount">
              <el-input
                v-model="queryParams.drugCount"
                placeholder="请输入采购单据号"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="药品名称" prop="drugName">
              <el-input
                v-model="queryParams.drugName"
                placeholder="请输入药品名称"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="药品类型" prop="drugType">
              <el-input
                v-model="queryParams.drugType"
                placeholder="请输入药品类型"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="生产厂家" prop="drugFactory">
              <el-input
                v-model="queryParams.drugFactory"
                placeholder="请输入生产厂家"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="处方类型" prop="drugRecipe">
              <el-input
                v-model="queryParams.drugRecipe"
                placeholder="请输入处方类型"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="dateRange"
                size="small"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table v-loading="loading" :data="batchList" @selection-change="handleSelectionChange">
            <!--<el-table-column type="selection" width="55" align="center" />-->
            <el-table-column label="药品ID" align="center" prop="drugId" />
            <el-table-column label="药品名称" align="center" prop="drugName" />
            <el-table-column label="采购量" align="center" prop="drugNum" />
            <el-table-column label="批发价" align="center" prop="drugPrice" />
            <el-table-column label="批发额" align="center" prop="drugMoney" />
            <el-table-column label="批次号" align="center" prop="drugCount" />
            <el-table-column label="生产厂家" align="center" prop="drugFactory" />
            <el-table-column label="药品类型" align="center" prop="drugType" />
            <el-table-column label="处方类型" align="center" prop="drugRecipe" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </template>
    </el-tab-pane>
  </el-tabs>
</template>
<script>
  import { BatchList } from "@/api/drug/batch";
  import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/drug/info";

  export default {
    name: "Post",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 科室表格数据
        postList: [],
        // 科室表格数据
        batchList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          postCode: undefined,
          postName: undefined,
          status: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };

    },
    created() {
      this.getList();
      this.getBatch();
      this.getDicts("sys_normal_disable").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      /** 查询批次列表 */
      getList() {
        this.loading = true;
        listPost(this.queryParams).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 查询批次列表 */
      getBatch() {
        this.loading = true;
        BatchList(this.queryParams).then(response => {
          this.batchList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 科室状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          postId: undefined,
          postCode: undefined,
          postName: undefined,
          postSort: 0,
          status: "0",
          remark: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  };
</script>

